from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver import ActionChains
import time
d = webdriver.Chrome()
d.maximize_window()
d.get('https://www.baidu.com')

set = d.find_element(By.CSS_SELECTOR,'[id="s-usersetting-top"]')
ActionChains(d).move_to_element(set).perform()
time.sleep(1)
mset = d.find_element(By.CSS_SELECTOR,'[class="setpref first"] [class="set"]')
mset.click()
time.sleep(1)
baset = d.find_element(By.LINK_TEXT,'保存设置')
baset.click()
time.sleep(1)
# 警告框处理  switch_to.alert
msg = d.switch_to.alert.text  # 获取警告框的文本
# d.switch_to.alert.dismiss()  # 关闭警告框
d.switch_to.alert.accept()  # 确认警告框
print(msg)


time.sleep(8)
d.quit()